package net.valyrian.game.pantallaInicio;

import static com.badlogic.gdx.scenes.scene2d.actions.Actions.moveTo;
//import static com.badlogic.gdx.scenes.scene2d.actions.Actions.run;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.sequence;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.List;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;

public class Levels implements Screen {

	private Stage stage;
	private Table table;
	private Skin skin;
	
	@Override
	public void render(float delta) {
		Gdx.gl.glClearColor(0, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		
		stage.act(delta);
		stage.draw();
		Table.drawDebug(stage);
	}

	@Override
	public void resize(int width, int height) {
		
		//table.setSize(width, height);
		//table.setFillParent(true);
		stage.setViewport(width, height, false);
		table.invalidateHierarchy();
//		table.setBounds(0, 0, width, height);
//		table.getCell(scrollPane).width(width/3);
//		table.getCell(play).width(width/3);
	}

	@Override
	public void show() {
		stage = new Stage();
		Gdx.input.setInputProcessor(stage);
		
		
		skin = new Skin(Gdx.files.internal("ui/menuSkin.json"),new TextureAtlas("ui/atlas.pack"));
		
		table = new Table(skin);
		table.setFillParent(true);
		//table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
		table.debug();
		
		List list = new List(new String[]{"UNO", "DOS", "TRES", "CUATRO", "CINCO", "SEIS", "SIETE", "OCHO", "NUEVE", "DIEZ", "Y MUCHOS MAS...", "UNO", "DOS", "TRES", "CUATRO", "CINCO", "SEIS", "SIETE", "OCHO", "NUEVE", "DIEZ", "Y MUCHOS MAS...", "UNO", "DOS", "TRES", "CUATRO", "CINCO", "SEIS", "SIETE", "OCHO", "NUEVE", "DIEZ", "Y MUCHOS MAS..."}, skin);
		
		ScrollPane scrollPane = new ScrollPane(list, skin);
		
	TextButton	play = new TextButton("JUGAR", skin);
	play.addListener(new ClickListener(){
		@Override
		public void clicked(InputEvent event, float x, float y) {
			super.clicked(event, x, y);
			((Game) Gdx.app.getApplicationListener()).setScreen(new Play());
		}
		
		
	});
	
	TextButton		back = new TextButton("REGRESAR", skin);
		back.addListener(new ClickListener(){
			@Override
			public void clicked(InputEvent event, float x, float y) {
				super.clicked(event, x, y);
				((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu());			
			}		
		});
		back.scale(0.5f);
		play.pad(10);
		back.pad(10);
		table.add("SELECCIONAR NIVEL").colspan(3).center().row();
		table.add(scrollPane).uniformX().left().top();
		table.add(play).uniformX();
		table.add(back).uniformX().expand().bottom().right();
		//table.row();
		stage.addActor(table);
		stage.addAction(sequence(moveTo(0, stage.getHeight()), moveTo(0, 0, .5f)));
		
		
		
		
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub

	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		stage.dispose();
		skin.dispose();

	}

}
